﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject.Business;

namespace eProject.Web.UI.Admin
{
    public partial class AirportManagementAddNew : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            loadData();
        }
        private void loadData() {
            List<Cities> city = Cities.GetAll();
            ddlCity.DataSource = city;
            ddlCity.DataTextField = "Name";
            ddlCity.DataValueField = "Id";
            ddlCity.DataBind();
        }
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.btnSubmit.ServerClick += new EventHandler(btnSubmit_Click);
            this.btnReset.ServerClick += new EventHandler(btnReset_Click);
        }
        public void btnReset_Click(object sender, EventArgs e) {
            txtAirportCode.Text = "";
            txtAirportName.Text = "";
        }
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string airportid = txtAirportCode.Text.Trim().ToString();
            string airportname = txtAirportName.Text.Trim().ToString();
            int cityId = int.Parse(ddlCity.SelectedValue.ToString());
            AirPorts airport = new AirPorts();
            airport.AirPortId = airportid;
            airport.Name = airportname;
            airport.CityId = cityId;
            airport.Save();
            Response.Redirect("AirportsManagementPro.aspx");
            Response.Write("Insert");
        }
    }
}